/* ****************************************************************************
 *
 * Copyright (c) Microsoft Corporation. 
 *
 * This source code is subject to terms and conditions of the Microsoft Public License. A 
 * copy of the license can be found in the License.html file at the root of this distribution. If 
 * you cannot locate the  Microsoft Public License, please send an email to 
 * dlr@microsoft.com. By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 *
 * You must not remove this notice, or any other, from this software.
 *
 * THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
 * PARTICULAR PURPOSE.
 * ***************************************************************************/

#if !defined(AFX_PGLBAR_H__86F60D96_6E52_4CEE_92A6_CBC180576435__INCLUDED_)
#define AFX_PGLBAR_H__86F60D96_6E52_4CEE_92A6_CBC180576435__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <pgl/core/PGLLine1D.h>
#include <pgl/core/PGLLegend.h>

/*! \brief A bar graph.

  This object is under construction.
	\todo Drawing code.
	\todo implement ETypeStacked
	\ingroup PGLObjectGroup
*/
class PGLCORE_EXT_CLASS CPGLBar : public CPGLObject
{
PGL_DECLARE_DYNCREATE(CPGLBar);
public:
	
	//! Different type of bar graph
	enum EType
	{
		//! Datas are shown side by side. (Default behavior)
		ETypeSideBySide = 1,
		//! Data series are stacked
		ETypeStacked = 2
	};

	//! \name Constructors
	//@{
	//! Default constructor
	CPGLBar(EType eType = ETypeSideBySide);
	//! Copy constructor
	CPGLBar( const CPGLBar& b)	{	*this = b;};
	//! Assignement constructor
	CPGLBar& operator= (const CPGLBar& b);
	virtual ~CPGLBar();
	//@}

	//! \name Not used yet
	//@{
	std::vector<CString>& GetXLabels()									{	return m_vXLabels;};
	const std::vector<CString>& GetXLabels() const						{	return m_vXLabels;};
	void SetXLabels( const 	std::vector<CString>& vLabels ){ m_vXLabels = vLabels;};

	const CPGLDataPtr GetXPositions() const			{	return m_pX;};
	CPGLDataPtr GetXPositions()						{	return m_pX;};
	void SetXPositions( CPGLDataPtr pXs);	
	//@}

	//! \name Data series handling
	//@{
	//! returns the number of series
	size_t GetSeriesSize() const	{	return m_lSeries.size();};
	//! return the series
	CPGLLine1DList& GetSeries()						{	return m_lSeries;};
	//! return the series, const
	const CPGLLine1DList& GetSeries() const			{	return m_lSeries;};
	//! Adds a serie to the front of the serie list
	void PushFront( CPGLLine1DPtr pSerie );
	//! Adds a serie to the tail of the serie list
	void PushTail( CPGLLine1DPtr pSerie );
	//! Delete all series
	void Clear();
	//! return the minimum size of all serie vectors
	size_t GetMinimumDataLength() const;
	//@}

	//! \name Bar type and customization
	//@{
	//! return the type of bar graph
	EType GetType() const		{	return m_eType;};
	//! sets the number of pixels between two bar groups
	void SetPixelInter(double dPixelInter)	{	m_dPixelInter = __max(0, dPixelInter);};
	//! return the number of pixels between two bar groups
	double GetPixelInter() const			{	return m_dPixelInter;};
	//! returns the bar width, in pixels
	float GetBarWidth(const gfxinterface::CGfxInterface& gfx, size_t nBars) const;
	float GetBarXStart(const gfxinterface::CGfxInterface& gfx, size_t nBars, double dBarWidthPixel) const;
	//@}

	//! \name Virtual functions
	//@{
    //! returns the extent of the datas
    virtual void GetUnionExtent(gfxinterface::CGfxInterface& gfx, CPGLRectD& rExtent);
    ///virtual function to override in derived classes
    virtual void UpdateExtent(gfxinterface::CGfxInterface& gfx);
	// plot function
	virtual void PlotGfx(gfxinterface::CGfxInterface& gfx);
	//! Add lines to legend
	void PushLinesTop(CPGLLegendPtr pLegend);
	//@}

	//! \name Serialization and debugging
	//@{
	//! Serialize functions
	void SerializeXML(CPGLArchive& ar);

	//! Debuggin functions
	#ifdef _DEBUG
	    virtual void Dump( CDumpContext& dc ) const;
	    virtual void AssertValid() const;   
	#endif
	//@}

protected:
	//! \name Attributes
	//@{
	//! string labels
	std::vector<CString> m_vXLabels;
	//! data series
	CPGLLine1DList m_lSeries;
	//! x position (optional)
	CPGLDataPtr m_pX;
	//! Number of pixels between data chunk
	double m_dPixelInter;
	//! type of chart
	EType m_eType;
	//@}
};


PGL_DECLARE_SMARTPTR( CPGLBar );

#endif // !defined(AFX_PGLBAR_H__86F60D96_6E52_4CEE_92A6_CBC180576435__INCLUDED_)
